import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    list:[], //数据
    //权限管理板块
    roleList:[], //角色列表数据
  },
  getters: {
  },
  mutations: {
    clear(state,obj){  //初始数据
      state.list = obj
    },

    seek(state,obj){  //搜索查询
      state.list = state.list.filter((item)=>item.username.includes(obj))
    },
  
    role(state,obj){  //存放角色列表数据
      state.roleList = obj
      // console.log(state.roleList);
    },

    delrole(state,id){  //删除角色单个权限
      // console.log(id);
    state.roleList.forEach((item)=>{
    //  console.log(item);
     item.children.forEach((obj,index)=>{
      if(obj.id == id){
        // console.log(index);
        // console.log(item.children);
        item.children.splice(index,1)
        return false
      }

      obj.children.forEach((val,index)=>{
        if(val.id == id){
          obj.children = {}
          return false
        }
          // console.log('走了');
          val.children.forEach((exi,index)=>{
            if(exi.id == id){
              // console.log(val.children);
              val.children.splice(index, 1)
            }
          })
      })
     })
    })

      
    }
  },
  actions: {
  },
  modules: {
  }
})
